package com.audaque.springboot.foshanupload.minio.config;

import com.audaque.springboot.foshanupload.minio.properties.MinIoProperties;
import io.minio.MinioClient;

import lombok.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * @author zgb
 * @desc ...
 * @date 2022-03-27 22:32:24
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Component
@ConditionalOnProperty(value = "switch.minio",havingValue = "true",matchIfMissing = false)
public class MinIoClientConfig {

    @Autowired
    private MinIoProperties minIoProperties;

    /**
     * 注入minio 客户端
     * @return
     */
    @Bean
    public MinioClient minioClient(){
        return MinioClient.builder()
                .endpoint(minIoProperties.getEndpoint())
                .credentials(minIoProperties.getAccessKey(), minIoProperties.getSecretKey())
                .build();
    }
}
